#include "common.h"
#include "console.h"
#include "document.h"
#include "insertcontroller.h"
#include "cppvi.h"

InsertController::InsertController(Console *console): Controller(console)
{

}

InsertController::~InsertController()
{

}

bool InsertController::processMessage(chtype message)
{
	Document *document = CppVi::getInstance()->getDocument();
	switch(message)
	{
	case keyesc:
		this->activeConsole->setController(this->activeConsole->getCommandController());
		this->activeConsole->update();
		break;
	case keyenter:
		document->feedLine();
		break;
	case keytab:
		document->keytab();
		break;
	case KEY_NPAGE:
		document->keypagedown();
		break;
	case KEY_PPAGE:
		document->keypageup();
		break;
	case KEY_UP:
		document->moveOffset(-1, 0);
		break;
	case KEY_DOWN:
		document->moveOffset(1, 0);
		break;
	case KEY_LEFT:
		document->moveOffset(0, -1);
		break;
	case KEY_RIGHT:
		document->moveOffset(0, 1);
		break;
	case KEY_BACKSPACE:
		document->backspace();
		break;
	case keydelete:
		document->keydelete();
		break;
	case KEY_HOME:
		document->keyhome();
		break;
	case KEY_END:
		document->keyend();
		break;
	default:
		document->add(message);
		break;
	}
	this->activeConsole->update();
	return true;
}

int InsertController::getMode() const
{
	return insertMode;
}
